package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.apache.shiro.crypto.hash.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    /**
     * 分页查询供应商
     * @param page
     * @param rows
     * @param supplierName
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> getPage(Integer page, Integer rows, String supplierName){
        List<Supplier> supplierList =  supplierService.getPage(page,rows,supplierName);
        HashMap<String, Object> result = new HashMap<>();
        result.put("total",supplierList.size());
        result.put("rows",supplierList);
        return result;
    }

    /**
     * 供应商添加或修改
     * @return
     */
    @PostMapping("/save")
    public ServiceVO save(@RequestParam("supplierId") Long supplierId, Supplier supplier){
        supplierService.update(supplierId,supplier);
        return new ServiceVO(100,"请求成功");
    }

    /**
     * 删除供应商
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO delete(String ids){
        supplierService.delete(ids);
        return new ServiceVO(100,"请求成功");
    }


    /**
     * 供应商下拉列表查询,供应商名称模糊查询
     * @param q
     * @return
     */
    @PostMapping("getComboboxList")
    public List<Supplier> getComboboxList(String q){
        List<Supplier> list = supplierService.getComboboxList(q);
        return list;
    }




}
